﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using System.Web.Security;

namespace IHISCETeim.Web.Export
{
    public partial class login : System.Web.UI.Page
    {
        protected string GetUserIP()
        {
            //string user_IP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            //return user_IP;
            string _userIP;
            if (Request.ServerVariables["HTTP_VIA"] == null)//未使用代理
            {
                _userIP = Request.UserHostAddress;
            }
            else//使用代理服务器
            {
                _userIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            }
            return _userIP;
        }



        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (Request.GetRequestValue<string>("errormsg", true, "") != "")
            {
                this.ltMsg.Text = Request.GetRequestValue<string>("errormsg");
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            //if (txtValCode.Text.ToLower().Trim() != Session["checkValidateCode"].ToString().ToLower())
            //{
            //    ResponseLoginErrMsg("验证码输入错误.");

            //    return;
            //}
            //else
            //{
            string loginIP = Request.UserHostAddress;
            int UserType = 0;
            LoginState loginstate = OUserController.Login(this.txtUserName.Text.Trim(), this.txtPassWord.Text.Trim().ToLower(), loginIP,ref UserType);

            switch (loginstate)
            {
                case LoginState.success:
                    Response.Redirect(Request.GetRequestValue<string>("ReturnUrl"));
                    break;
                case LoginState.inputerror:
                    this.ltMsg.Text = "用户名或密码输入错误.";
                    break;
                case LoginState.other:
                    this.ltMsg.Text = "登陆失败.该用户可能被禁用！";
                    break;
            }
            //}
        }
    }
}